package com.cunjin.dormitory.comtroller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cunjin.base.controller.BaseController;
import com.cunjin.dormitory.entity.DormitoryEntity;
import com.cunjin.dormitory.service.DormitoryService;

@Controller
@RequestMapping("/dormitory")
public class DormitoryComtroller extends BaseController<DormitoryEntity> {

	@Autowired
	private DormitoryService service;
	
		
	//http://localhost:8090/cunjin-dorm/dormitory/manren
	@RequestMapping("/manren")
	@ResponseBody
	public Map<String, Object> manren(DormitoryEntity entity) {
		
		Map<String, Object> all = service.queryRenShu(entity);
		return all;
	}
	
	//拿到所有宿舍给下拉框用
	@RequestMapping("/getcommoBox")
	@ResponseBody
	public List<DormitoryEntity> getcommoBox(DormitoryEntity entity) {
		
		List<DormitoryEntity> all = service.getcommoBox();
		return all;
	}
	
	
	@RequestMapping("/myInsert")
	@ResponseBody
	public Map<String, Object> myInsert(DormitoryEntity entity) {
		
		Map<String, Object> insert = service.insert(entity);
		return insert;
	}
	
	/**
	 * 分页
	 * @param page
	 * @param rows
	 * @param searchName
	 * @return
	 */
	@RequestMapping("/findWithPage")
	@ResponseBody
	public Map<String, Object>  findWithPage(int page,int rows,String searchName) {
	
		Map<String, Object>  fy = service.queryByPage(page,rows,searchName);
		return fy;
	}
	
	/**
	 * 添加一个宿舍
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/addDormitory")
	@ResponseBody
	public Map<String, Object> addDormitory(DormitoryEntity entity) {
		
		Map<String, Object>  map = service.insert(entity);
				return map;
	}
	
	
	/**
	 * 
	 * 删除
	 * @param dles
	 * @return
	 */
	@RequestMapping("/delDormitory")
	@ResponseBody
	public Map<String, Object>  delDormitory(String dles) {
		
		String[] split = dles.split(",");
		Map<String, Object>  mydelete = service.deleteByids(split);
		return mydelete;
	}

	/**
	 * 更新
	 * @param entity
	 * @return
	 */
	@RequestMapping("/updateDormitory")
	@ResponseBody
	public Map<String, Object>  updateDormitory(DormitoryEntity entity) {
		
		Map<String, Object>  myupdate = service.update(entity);
		return myupdate;
	}
	

	
}
